<?php

namespace App\Http\Controllers;

use App\Services\ChannelService;
use Illuminate\Http\Request;

class ChannelController extends Controller
{

    protected $service;

    public function __construct()
    {
        $this->service = new ChannelService();
    }

    public function record(Request $request): \Illuminate\Http\JsonResponse
    {
        $type = $request->get('type') ?? 0;
        $time = $request->get('time') ?? 0;
        $appid = $request->get('appid') ?? '';

        $this->service->record($type, $time, $appid);

        if ($this->service->getErrMsg()) {
            return response()->json(['status' =>  'fail', 'msg' => $this->service->getErrMsg()]);
        }

        return response()->json(['status' =>  'success', 'msg' => '']);
    }
}
